package com.test;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Properties;

import org.hibernate.Query;
import org.hibernate.Session;

import com.group1.model.Lecturer;
import com.group1.model.Subject;
import com.group1.util.SessionFactoryUtil;
public class testSubject {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
//				Session session = SessionFactoryUtil.getSessionFactory().getCurrentSession();
//				 session.beginTransaction();
//				createSubject(session);
//				System.out.print("Finish Create");
//				querySubject(session);
		//		updateSubject(session);
				//deleteSubject(session);
				//querySubject(session);
//				System.out.print("Finish Query");
//				updateSubject(session);
//				System.out.print("Finish Update");
//				session.getTransaction().commit();
		Properties prop = new Properties();
		try {
			prop.load(new FileInputStream("config.properties"));
			String s = prop.getProperty("ImagePath");
			System.out.println(s);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

private static void querySubject(Session session) {
		
		Collection<Subject> list = Subject.getSubjectByLecturer("lecturer1",session);
		java.util.Iterator<Subject> iter = list.iterator();
		while (iter.hasNext()) {
			Subject s = iter.next();
		System.out.println("ID: \"" + s.getSubjectId() +"\", Name" +s.getSubjectName() + ", creadit: " + s.getSubjectCredits());
		}
		
	}
	public static void updateSubject(Session session)
	{
	//	Subject s = Subject.getSubjectByID("SJ1", session);
	//	s.setSubjectName("NEW SUBJECT NAME !!!");
	//	session.saveOrUpdate(s);
	//	s.updateSubject(session);
	}
	
	public static void deleteSubject(Session session)
	{
	//	Subject s = Subject.getSubjectByID("SJ3", session);
	//	session.delete(s);
	//	s.deleteSubject(session);
	}
	public static void createSubject(Session session) {
	 	Subject s = new Subject();
	 	int num = 3;
		s.setSubjectId("SN" + num);
		s.setSubjectName("name" +num);
		s.setSubjectShortname("SN"+num);
		s.setSubjectCredits(1);
		s.getLecturerSubjectMapping().add(Lecturer.getLecturerByID(session, "lecturer1"));
		session.save(s);
	}
}
